/*
 * @Description: 配置
 * @Author: chenju
 * @Date: 2022-01-14 14:46:49
 * @LastEditors: chenju
 * @LastEditTime: 2023-01-17 16:33:58
 */
import { reactive } from 'vue'
import type {
  SearchOptionsType,
  CPageTableProps,
  ColumnSettingTypeEnum
} from '@/components/CPageTable'
import type { CTableProps } from '@/components/CTable'
import { getSupplierUserList } from '@/apis/system/config/supplier'
import type { GetUsersListParams } from '@/apis/system/model/userModel'
import type { BasicPagingListParams } from '@/apis/basicModel'
import { useRoute } from 'vue-router'

export const useFactorList = () => {
  const route = useRoute()
  const supplierNo = route.query.supplierNo as any
  // 搜索字段及其他
  const searchForm = reactive<GetUsersListParams>({
    realName: ''
  })

  // 搜索配置
  const searchOptions: SearchOptionsType[] = []

  // 表格配置
  const tableOptions: CTableProps = {
    loadData
  }

  function loadData(parameter: BasicPagingListParams) {
    const params = {
      enterpriseNo: supplierNo,
      ...parameter
    }
    return getSupplierUserList(params)
  }

  // 处理参数

  const tableFieldsSetting: CPageTableProps['tableFieldsSetting'] = [
    {
      title: '用户名称',
      field: 'realName',
      slot: 'realNameSlot',
      minWidth: '150',
      columnSettingConfig: {
        enabled: true,
        type: ColumnSettingTypeEnum.REQUIRED
      }
    },
    {
      title: '登录邮箱',
      field: 'email',
      minWidth: '200',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '手机号',
      field: 'phone',
      width: '160',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '创建人/创建时间',
      field: 'createBy',
      slot: 'creatorSlot',
      width: '160',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      key: 'op',
      title: '操作',
      field: 'op',
      slot: 'op',
      width: '150',
      fixed: 'right',
      columnSettingConfig: {
        enabled: true,
        type: ColumnSettingTypeEnum.FIXED
      }
    }
  ]

  return {
    // 头部右侧筛选项配置
    searchOptions,
    // 筛选项字段
    searchForm,
    // 表格配置
    tableOptions,
    tableFieldsSetting
  }
}
